package com.metis.document.parse.dialog.models.dto;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

import com.metis.document.parse.dialog.enums.ElementTypeEnum;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
import org.jetbrains.annotations.NotNull;

/**
 * @author: wuzhijun
 * @date: 2022/11/28
 */
@Data
@EqualsAndHashCode(callSuper = false)
@SuperBuilder
@AllArgsConstructor
@NoArgsConstructor
public abstract class AbstractElementDTO implements Comparable<AbstractElementDTO>  {
    private Double x;
    private Double y;
    private Double width;
    private Double height;
    @Builder.Default
    private final List<TagEnums> tags = new ArrayList<>();
    /**
     * 从1开始
     */
    private Integer page;
    /**
     * 从1开始
     */
    private Long line;
    private ElementTypeEnum type;

    @Override
    public int compareTo(@NotNull AbstractElementDTO o) {
        if (!Objects.equals(page, o.page)) {
            return page - o.page;
        }
        if (Double.compare(y, o.getY()) != 0) {
            return Double.compare(y, o.getY());
        }
        if (Double.compare(x, o.getX()) != 0) {
            return Double.compare(x, o.getX());
        }
        return type.compareTo(o.type);
    }

}
